import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:xvideos/hj_model/home/module_detail_model.dart';
import 'package:xvideos/tools_base/widget/net_image_widget.dart';
import 'package:xvideos/hj_utils/widget_utils.dart';

class SourceSectionView extends StatefulWidget {
  final List<AllSection> sections;

  final Function()? moreCick;
  const SourceSectionView(this.sections, {super.key, this.moreCick});

  @override
  State<SourceSectionView> createState() => _SourceSectionViewState();
}

class _SourceSectionViewState extends State<SourceSectionView> {
  late AllSection? selectSection = widget.sections.firstOrNull;
  @override
  Widget build(BuildContext context) {
    if (widget.sections.isEmpty) SizedBox.shrink();
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Padding(
          padding: EdgeInsets.symmetric(horizontal: 18.w),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              GestureDetector(
                onTap: () {
                  widget.moreCick?.call();
                },
                child: Row(
                  children: [
                    Text(
                      '小编推荐',
                      style: TextStyle(color: Colors.white, fontWeight: FontWeight.w900, fontSize: 18.sp),
                    ),
                    Spacer(),
                    Text(
                      '更多',
                      style: TextStyle(color: Color(0xff999999), fontWeight: FontWeight.w400, fontSize: 12.sp),
                    ),
                  ],
                ),
              )
            ],
          ),
        ),
        12.sizeBoxH,
        Padding(
          padding: EdgeInsets.only(left: 18.w),
          child: SizedBox(
            height: 80.w + 4 + 20,
            child: ListView.separated(
              shrinkWrap: true,
              separatorBuilder: (_, __) => 14.sizeBoxW,
              scrollDirection: Axis.horizontal,
              itemCount: widget.sections.length,
              itemBuilder: (BuildContext context, int index) {
                final model = widget.sections[index];
                return GestureDetector(
                  onTap: () {
                    // showToast('跳转专题详情');
                    // Get.toNamed(AcgSectionDetailPage.routeName, arguments: model);
                  },
                  child: Column(
                    children: [
                      NetworkImageLoader(
                        imageUrl: model.sectionCover ?? '',
                        width: 80.w,
                        height: 80.w,
                      ),
                      4.sizeBoxH,
                      Text(
                        model.sectionName ?? '',
                        style: TextStyle(color: Colors.white.withOpacity(.6), fontSize: 14),
                      )
                    ],
                  ),
                );
              },
            ),
          ),
        )
      ],
    );
  }
}
